package cn.school.thoughtworks.section1;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class PracticeA {
    List<String> collectSameElements(List<String> collection1, List<String> collection2) {
        //实现练习要求，并改写该行代码。
        //法一
        /*List<String> sameElements = new ArrayList<>();
        for (String elementInCollection1 : collection1){
            boolean collecton2ContainsElement = collection2.contains(elementInCollection1);
            if (collecton2ContainsElement){
                sameElements.add(elementInCollection1);
            }
        }
        return sameElements;*/
        //法2
        return collection1.stream()
                .filter(element -> collection2.contains(element) )
                .collect(Collectors.toList());




    }
}
